<?php
class product_model extends CI_Model
{
    protected $_table = "mock_products";
    public function __construct(){
        parent::__construct();
    }
    public function update($id,$data){
        $this->db->where("product_id",$id);
        $this->db->update($this->_table,$data);
    }
    public function getdata($id){
        $this->db->where("product_id",$id);
        return $this->db->get($this->_table)->row_array();
    }
    public function addProduct($data){
        $this->db->insert($this->_table,$data);
    }
    function save_image($field,$filename=''){

        if($filename!=''){
            $data[$field] = $filename;
        }
        $this->db->where('id',1);// item  id
        $this->db->update($this->_table,$data);
    }
    function count_all() {
        return $this->db->count_all('mock_products');
    }

    public function list_all($off,$start)
    {
        $this->db->limit($off,$start);
        return $this->db->get($this->_table)->result_array();
    }
    public function getProduct($id)
    {
        $this->db->where("product_id",$id);
        return $this->db->get($this->_table)->row_array();

    }
    public function checkName($data){
        $this->db->where("product_name",$data);
        $numName = $this->db->count_all_results($this->_table);
        if($numName >0){
            return FALSE;
        }else{
            return TRUE;
        }
    }
    public function deleteProduct($id){
        $this->db->delete($this->_table,array('product_id'=>$id));
    }

}